import { useStorage } from "./useStorage";

export function useDeviceUuid(): string {
    const deviceUuid = useStorage().get('deviceUuid', undefined);
    if (deviceUuid) return deviceUuid
    const newDeviceId = useUuid();
    useStorage().put('deviceUuid', newDeviceId);
    return newDeviceId
}


function useUuid() {
    function S4() {
        return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
    }
    return (S4() + S4() + "-" + S4() + "-" + S4() + "-" + S4() + "-" + S4() + S4() + S4());
}